<?php

namespace app\models\Wechat;

use Yii;

/**
 * This is the model class for table "user_access_token".
 *
 * @property string $access_token
 * @property integer $create_time
 */
class UserAccessToken extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_access_token';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_time','id'], 'integer'],
            [['access_token'], 'string', 'max' => 255],
            [['jsapi_ticket'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' =>'ID',
            'access_token' => 'Access Token',
            'create_time' => 'Create Time',
            'jsapi_ticket' => 'Jsapi_Ticket',
        ];
    }
    /*
     * 存储token
     */
    public function setToken($access_token,$create_time,$jsapi_ticket)
    {
        $tokens = $this->find()
                    ->where(['id' => 1])
                    ->one();
            $tokens->access_token = $access_token;
            $tokens->create_time = $create_time;
            $tokens->jsapi_ticket = $jsapi_ticket;
            return $tokens->save();
    }
    
    /*
     * 查询token
     */
    public function getToken()
    {
        $list = $this->find()
                ->where(['id' => 1])
                ->asArray()
                ->One();
        return $list;
    }
    
}
